package topcbl.util;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JSONParseDistanceAndTime {
	String data;

	public JSONParseDistanceAndTime(String data) {
		this.data = data;
	}

	public String[] parse() {
		JSONObject obj;
		JSONArray arr;
		try {
			obj = new JSONObject(data);
			arr = obj.getJSONArray("routes");
			obj = arr.getJSONObject(0);
			arr = obj.getJSONArray("legs");
			obj = arr.getJSONObject(0);
			JSONObject objDis = obj.getJSONObject("distance");
			JSONObject objTime = obj.getJSONObject("duration");
			return new String[] { objDis.getString("text"),
					objTime.getString("text") };
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
}
